﻿using UnityEngine;
using System.Collections;

public class CharatorPanel : Inventory 
{
    private CharatorSlot[] charatorSlotList;

    private static CharatorPanel _instance;

    public static CharatorPanel GetInstance
    {
        get
        {
            if (_instance == null)
            {
                _instance = GameObject.Find("CharatorPanel").GetComponent<CharatorPanel>();
            }

            return _instance;
        }
    }
    
    protected override void Start()
    { 
        charatorSlotList=this.GetComponentsInChildren<CharatorSlot>();
    }

    void Update()
    {
        foreach (CharatorSlot slot in charatorSlotList)
        {
            if (slot.transform.childCount != 0)
            {
                if (slot.transform.GetChild(0).GetComponent<GoodUI>().good is Equipment)
                {
                    if (slot.equitmentType != ((Equipment)(slot.transform.GetChild(0).GetComponent<GoodUI>().good)).equitmentType)
                    {
                        GoodUI gu = slot.transform.GetChild(0).GetComponent<GoodUI>();

                        KnapsackPanel.GetInstance.StoreGood(gu.good.goodProperty.ID);
                        Destroy(slot.transform.GetChild(0).gameObject);
                    }
                }
                else if (slot.transform.GetChild(0).GetComponent<GoodUI>().good is Weapon)
                {
                    if (slot.weaponType != ((Weapon)(slot.transform.GetChild(0).GetComponent<GoodUI>().good)).weaponType)
                    {
                        GoodUI gu = slot.transform.GetChild(0).GetComponent<GoodUI>();

                        KnapsackPanel.GetInstance.StoreGood(gu.good.goodProperty.ID);
                        Destroy(slot.transform.GetChild(0).gameObject);
                    }
                }
                
            }          
        }
    }
}
